<template>
  <div class="app-container">
    <!-- 工具栏 -->
    <!-- <tl-list-toolbar ref="toolbar" :isDisplayAdd="editable" :isDisplayExport="false" :isDisplayDeleteBatch="editable" @add="openAddDialog('editForm')" @exportExcel="doExportExcel" @deleteBatch="doDeleteBatch" @refresh="doRefresh" @columnCustomize="doColumnCustomize" @displaySearch="doDisplaySearch" :disableDeleteBatch="selectedRowKeys.length <= 0">
      <template slot="left-btn">
        <el-button class="filter-item" type="primary" icon="el-icon-plus" @click="openAddDialog('editTemplateForm')" v-show="editable">按模板新增</el-button>
        <el-button class="filter-item" type="primary" icon="el-icon-plus" :projectinfo="projectinfo" @click="openAddDialog('editProjectForm')" v-show="editable">按项目新增</el-button>
      </template>
    </tl-list-toolbar> -->
    <div style="margin-top:6px">
      <!-- 列表选择 -->
      <div class="table-alert-div" ref="selector">
        <el-alert type="success" :closable="false" class="tl-table-alert-info" effect="light">
          <template slot="title">
            已选择&nbsp;<a class="tl-table-alert-info-a1">{{ selectedRowKeys.length }}</a
            >项&nbsp;&nbsp;
            <a class="tl-table-alert-info-a2" @click="doClearSelected">全部清空</a>
          </template>
        </el-alert>
      </div>
      <!--表格渲染-->
      <el-table class="tl-table" ref="mainTable" :height="tableHeight" resizable-key="tableHeight" :resizable-refs="tableResizeRefs" v-loading="loading" :row-style="tableRowStyle" :data="datas" @selection-change="doSelectChange" @sort-change="doSortChange" @row-dblclick="doRowDbClick" @row-click="doRowClick" row-key="id" border fit :row-class-name="doChangeRowClassName">
        <el-table-column type="index" label="序号" width="55px" align="center"></el-table-column>
        <el-table-column prop="milepostname" label="里程碑及任务名称" width="250px" sortable="custom" sort-by="milepostname" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="deliverable" label="交付成果" sortable="custom" sort-by="deliverable" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispmilepoststate" label="里程碑及任务状态" width="140px" sortable="custom" sort-by="milepoststate" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="responsible" label="责任人" width="120px" sortable="custom" sort-by="responsible" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="planfinishtime" label="计划达成日期" width="160px" sortable="custom" sort-by="planfinishtime" align="center" header-align="center" :show-overflow-tooltip="true" :formatter="dateFormat"></el-table-column>
        <el-table-column prop="actualfinishtime" label="实际达成时间" width="160px" sortable="custom" sort-by="actualfinishtime" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="supervise" label="督办情况" sortable="custom" sort-by="superviselist" align="left" header-align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <div v-if="scope.row.supervise !== '' && scope.row.supervise !== undefined">
              <div class="superviser" @click="openViewDialog('superviseeditForm', scope.row.supervise.id)">
                <span>{{ scope.row.supervise.supervisecode }}</span>
                <el-button class="superviserButton" :type="supervisecolor(scope.row.supervise.dispsupervisestate)" size="mini" plain>{{ scope.row.supervise.dispsupervisestate }}</el-button>
              </div>
            </div>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="sourcetype" label="来源类型" width="150px" sortable="custom" sort-by="sourcetype" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="sourceid" label="来源id" width="150px" sortable="custom" sort-by="sourceid" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="milepostcode" label="编码" width="150px" sortable="custom" sort-by="milepostcode" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="dispmilepoststate" label="里程碑及任务状态" width="100px" sortable="custom" sort-by="milepoststate" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="state" label="审批状态" width="150px" sortable="custom" sort-by="state" align="center" header-align="center" :show-overflow-tooltip="true"></el-table-column>
        <el-table-column prop="description" label="备注" min-width="250px" align="left" header-align="center" :show-overflow-tooltip="true"></el-table-column> -->
        <!-- <el-table-column prop="enabled" label="有效" width="100px" sortable="custom" sort-by="enabled" align="center" header-align="center">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.enabled === 1" type="success">是</el-tag>
            <el-tag v-else type="danger">否</el-tag>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="操作" width="100px" v-slot="scope" fixed="right">
          <el-dropdown trigger="hover">
            <el-button type="text" icon="el-icon-s-operation" style="margin-left:10px">更多<i class="el-icon-arrow-down el-icon--right"></i></el-button>
            <el-dropdown-menu>
              <el-dropdown-item icon="el-icon-edit" @click.native="openEditDialog('editForm', scope.row.id)" :disabled="scope.row.state !== 0 && scope.row.state !== 2">编辑</el-dropdown-item>
              <el-dropdown-item icon="el-icon-delete" :disabled="scope.row.milepoststate !== 1" @click.native="doDelete(scope.row.id)">删除</el-dropdown-item>
              <el-dropdown-item icon="el-icon-view" @click.native="openViewDialog('editForm', scope.row.id)">查看
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </el-table-column> -->
      </el-table>
      <!-- 列表分页 -->
      <el-row class="pagebar" ref="pager">
        <el-pagination @size-change="doChangeSize" @current-change="doChangeIndex" :current-page="pageInfo.currentPage" :page-sizes="pageInfo.pageSizes" :total="pageInfo.totalCount" layout="total, sizes, prev, pager, next, jumper" background class="tl-table-pagination"> </el-pagination>
      </el-row>
      <tl-supervise-edit ref="superviseeditForm" @refresh="doRefresh"></tl-supervise-edit>
      <tl-edit ref="editForm" @refresh="doRefresh" :parentId="parentId" :projectinfo="projectinfo"></tl-edit>
      <tl-edit-template ref="editTemplateForm" @refresh="doRefresh" :parentId="parentId" :projectinfo="projectinfo"></tl-edit-template>
      <tl-edit-project ref="editProjectForm" @refresh="doRefresh" :parentId="parentId" :projectinfo="projectinfo"></tl-edit-project>
    </div>
  </div>
</template>

<script>
/** mixins */
import { mixin_list } from '@tapui/mixins/mixin_list'
/** 子组件 */
import tlEdit from './edit'
import tlSuperviseEdit from '@/views/mpm/mpmProjectSupervise/editView'
import tlEditTemplate from './editTemplate'
import tlEditProject from './editProject'
import { validateNull } from '@tapui/utils/validate'
import { formatDate } from '@tapui/utils/date'
import { MPM_MILEPOST_STATE } from '@/const/const'
/** 工具类 */
import { getAction, putAction, postAction, deleteAction } from '@tapui/utils/http'
export default {
  name: 'mpmProjectMilepost',
  mixins: [mixin_list],
  components: { tlEdit, tlEditTemplate, tlEditProject, tlSuperviseEdit },
  data() {
    return {
      description: '项目策划-里程碑及任务-列表查询',
      urlPrefix: '/mpm/projectMilepost/',
      url: {
        // queryCodeList: '/mpm/projectMilepost/dataCodeList'
        list: '/mpm/projectMilepost/list',
        load: '/mpm/projectMilepost/load'
      },
      reduceHeight: 282,
      rowDbClickActionType: 'view',
      // 排序参数
      sorterInfo: {
        sidx: 'sortcode asc,planfinishtime asc,id',
        sord: 'asc'
      },
      datas: [],
      operatecode: '',
      datamsg: {}
    }
  },
  props: {
    parentId: {
      type: [Number, String],
      default: ''
    },
    editable: {
      type: Boolean,
      default: true
    },
    projectinfo: {}
  },
  methods: {
    supervisecolor(e) {
      if (e === '超期') {
        return { color: '#FF0000' }
      } else if (e === '已完成') {
        return { color: '#00FF00' }
      } else if (e === '进行中') {
        return { color: '#FFFF00' }
      }
    },
    /** 列表数据加载开始 */
    loadData(paramMap) {
      if (!this.url.list) {
        this.$tap.alert('请设置list地址!', 'warning')
        return
      }
      // 得到加载分页
      if (validateNull(paramMap) === false && Object.keys(paramMap).indexOf('currentPage') > -1) {
        this.pageInfo.currentPage = paramMap['currentPage']
      }
      if (!this.beforeLoadData()) return
      // 查询条件
      var params = this.getQueryParams()
      // 数据查询
      this.loading = true
      getAction(this.url.list, params)
        .then((res) => {
          if (res.success) {
            this.datas = res.result.dataList
            this.pageInfo.totalCount = res.result.totalCount
            // 初始化自定义列
            if (typeof this.$refs.toolbar !== 'undefined') {
              this.$refs.toolbar.doInitTableColumn()
            }
          } else {
            this.$tap.alert(res.message, 'warning')
          }
          this.afterLoadData()
          this.loading = false
        })
        .catch((err) => {
          this.loading = false
        })
    },
    initPage() {
      if (this.editable) {
        this.rowDbClickActionType = 'edit'
      } else {
        this.rowDbClickActionType = 'view'
      }
    },
    // 行颜色
    tableRowStyle(row, index) {
      // 如果计划完成时间为空，则行颜色为空
      if (row.row.planfinishtime === undefined || row.row.planfinishtime === null || row.row.planfinishtime === '') {
        return {}
      } else {
        let milepostState = row.row.milepoststate.toString()
        let currentTime = new Date()
        // 替换字符 变为标准格式
        let customTime = formatDate(new Date(row.row.planfinishtime.replace(new RegExp(/-/gm), '/')), 'yyyy-MM-dd 23:59:59')
        customTime = new Date(Date.parse(customTime))
        // 如果当前时间 > 计划达成日期
        if (currentTime > customTime && milepostState === MPM_MILEPOST_STATE.inComplete) {
          return { 'background-color': '#FF8C2E', color: '#FFFFFF' }
        }
      }
    },
    beforeLoadData() {
      this.queryParam.qry_projectcode = this.projectinfo.projectcode
      this.queryParam.qry_enabled = 1
      this.queryParam.qry_superviselist = true
      return true
    }
  }
}
</script>

<style scoped>
div.superviser:hover,
div.superviser:active {
  text-decoration: underline;
}
.app-container {
  margin: 0;
}
.superviser {
  display: flex;
}
.superviserButton {
  margin-left: 24px;
  display: flex;
  justify-content: center;
  align-items: center;
  width: 50px;
  height: 22px;
}
</style>
